package CommentTable;

import comment.Comment;
import page.PageClass;
import utils.JdbcUtils;

import javax.swing.*;
import java.time.LocalDateTime;

public class UpdataComment {
    public static void init(String name){
        JFrame frame=new JFrame();
        String info = JOptionPane.showInputDialog(frame,"要修改的评论id编号为:","输入",JOptionPane.WARNING_MESSAGE);
        if(JdbcUtils.JdbcQuery(Comment.sql_queryComment,info).isEmpty()){
            JOptionPane.showMessageDialog(frame,"id不存在");
        }else{
            String info2 = JOptionPane.showInputDialog(frame,"要修改内容为为:","输入",JOptionPane.WARNING_MESSAGE);
            int yn=JOptionPane.showConfirmDialog(frame, "确认修改该评论？", "确认框", JOptionPane.OK_CANCEL_OPTION);
            if(yn==JOptionPane.YES_OPTION){
                LocalDateTime time=LocalDateTime.now();
                JdbcUtils.JdbcUpdate(Comment.sql_updataCommentText,info2,info);
                JdbcUtils.JdbcUpdate(Comment.sql_updataCommentTime,time,info);
                PageClass.jssum();
                JOptionPane.showMessageDialog(frame, "修改成功");
            }
        }
    }
}
